package com.design.proxy.image;

// 图像代理类
class ImageProxy implements Image {
    private String filename;
    private RealImage realImage;

    public ImageProxy(String filename) {
        this.filename = filename;
    }

    @Override
    public void display() {
        if (realImage == null) {
            // 加载中的提示
            System.out.println("Displaying loading message...");
            // 模拟加载耗时
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 加载真实图片对象
            realImage = new RealImage(filename);
        }
        // 显示真实图片
        realImage.display();
    }
}